package com.example.mvpdemo.dao.manager;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.example.mvpdemo.dao.DaoMaster;
import com.example.mvpdemo.dao.DaoSession;
import com.example.mvpdemo.dao.UserDao;

public class DBManager {

    private DaoSession mDaoSession;

    private DBManager() {
    }

    public static DBManager getInstance() {
        return SingleTonHoler.instance;
    }

    private static class SingleTonHoler {
        private static DBManager instance = new DBManager();
    }


    public void init(Context context) {
        //创建数据库demo.db
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "demo.db");
        //获取可写数据库
        SQLiteDatabase database = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(database);
        //获取Dao对象管理者
        mDaoSession = daoMaster.newSession();
    }

    public UserDao getUserDao() {
        return mDaoSession.getUserDao();
    }
}
